<template>
  <div class="tab-control">
    <div
      v-for="(item, index) in titles"
      :key="item.id"
      class="tab-item"
      @click="tabChange(index)"
    >
      <h3 :class="{ active: index === currentIndex }">{{ item }}</h3>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      currentIndex: 0,
    };
  },
  props: {
    titles: {
      type: Array,
    },
  },
  methods: {
    tabChange(index) {
      this.currentIndex = index;
      this.$emit("tabClick", index);
    },
  },
};
</script>

<style lang="less" scoped>
.tab-control {
  display: flex;
  justify-content: space-around;
  .tab-item {
    height: 40px;
    line-height: 40px;
    h3 {
      padding: 0 10px;
    }
  }
}
.active {
  color: var(--color-tint);
  border-bottom: 2px solid #ff8198;
}
</style>